using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Autorun
{
	public partial class LogDialog : Form
	{
		#region "Members"
		private ServerManagement _proxy;
		private int _logId;
		private DataRowView row;
		#endregion

		#region "Constructor and Form's Events Handlers"
		public LogDialog()
		{
			InitializeComponent();
		}
		#endregion

		#region "Procedures
		public void SetData(ServerManagement proxy, int logId)
		{
			_proxy = proxy;
			_logId = logId;
			LoadData();
		}

		private void LoadData()
		{
			DataTable dt;

			if (_proxy != null)
			{
				dt = _proxy.Log.LogEntries;
				dt.DefaultView.RowFilter = string.Format("logId={0}", _logId);
				if (dt.DefaultView.Count != 0)
				{
					row = dt.DefaultView[0];
					txtTask.Text = row["tskCaption"].ToString();
					txtContext.Text = row["logKey"].ToString();
					txtDate.Text = row["logDateTime"].ToString();
					txtSeverity.Text = row["logSeverityCaption"].ToString();
					txtInfo.Text = row["logMessage"].ToString();

					lnkData.Visible = (row["logData"].ToString().Length != 0);
				}
			}
		}

		private void lnkData_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			txtInfo.Text = row["logData"].ToString();
			lnkMessage.Enabled = true;
			lnkData.Enabled = false;
		}

		private void lnkMessage_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			txtInfo.Text = row["logMessage"].ToString();
			lnkMessage.Enabled = false;
			lnkData.Enabled = true;
		}
		#endregion
	}
}